from itertools import combinations
import random

def find_covering_arrays(numbers):
    if len(numbers) != 16:
        raise ValueError("必须提供16个数字！")

    # 生成所有可能的6个数字组合
    all_combinations = list(combinations(numbers, 6))
    covering_arrays = []
    covered_combinations = set()

    while len(covered_combinations) < len(all_combinations):
        # 选择一个尚未被覆盖的6元子集
        for comb in all_combinations:
            if comb not in covered_combinations:
                selected_combination = comb
                break
        new_array = set(selected_combination)

        # 检查这个数组是否至少覆盖了一个6元子集
        newly_covered = False
        for comb in list(all_combinations):
            if comb not in covered_combinations and comb.issubset(new_array):
                covered_combinations.add(comb)
                newly_covered = True

        # 如果这个数组至少覆盖了一个6元子集，就加入到结果中
        if newly_covered:
            covering_arrays.append(new_array)

    return covering_arrays


if __name__ == "__main__":
    # 用户输入或随机生成16个数字
    user_input = input("请输入16个数字，用空格分隔 (或直接按Enter随机生成): ")
    if user_input.strip():
        numbers = list(map(int, user_input.split()))
        if len(numbers) != 16 or len(set(numbers)) != 16:
            print("输入无效！请提供16个不重复的数字。")
            exit(1)
    else:
        numbers = random.sample(range(1, 100), 16)

    print(f"使用的数字集合: {numbers}")

    # 生成满足条件的所有数组
    covering_arrays = find_covering_arrays(numbers)

    # 输出结果
    print(f"找到的覆盖数组数量: {len(covering_arrays)}")
    for i, arr in enumerate(covering_arrays, 1):
        print(f"数组 {i}: {arr}")